import {WeaSearchGroup, WeaFormItem} from 'ecCom';
import {WeaSwitch} from 'comsMobx';

export const getSearchs = (form, conditioninfo=[], onSearch=null, formName="", ecId="") => {
  const {
    isFormInit,
  } = form;
  let group = [];

  if (isFormInit) {
    let formParams = form.getFormParams(); // 获取表单的值

    isFormInit && conditioninfo.forEach((c, index) => {
      let items = [];

      c.items && c.items.forEach(fields => {
        items.push({
          com: (<WeaFormItem ecId={`${ecId || ''}_WeaFormItem@fh0yj7@${formName}${fields.domkey[0]}`}
            label={`${fields.label}`}
            labelCol={{span: `${fields.labelcol}`}}
            wrapperCol={{span: `${fields.fieldcol}`}}>
            <WeaSwitch ecId={`${ecId || ''}_WeaSwitch@wv55ke@${formName}${fields.domkey[0]}`} fieldConfig={fields} form={form} formParams={formParams} onEnterSearch={onSearch} />
          </WeaFormItem>),
          colSpan: 1
        })
      });
      group.push(<WeaSearchGroup ecId={`${ecId || ''}_WeaSearchGroup@pmrkdm@${formName}${index}`} needTigger={true} title={c.title} showGroup={true} items={items}/>)
    });
  }
  return group;
}